package com.ssyt.blog.core.sys.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ssyt.blog.core.common.PageModel;
import com.ssyt.blog.core.sys.dao.MenuDao;
import com.ssyt.blog.core.sys.dao.UserDao;
import com.ssyt.blog.core.sys.entity.Menu;
import com.ssyt.blog.core.sys.entity.User;

@Service
public class UserService {

	@Autowired
	private UserDao userDao;
	@Autowired
	private MenuDao menuDao;

	/**
	 * 新增一个用户，并记录日志
	 */
	// @Transactional
	// @Transactional(propagation = Propagation.REQUIRED)
	public void add(User user) {
		userDao.addUser(user);
	}

	/**
	 * <pre>
	 * @Transactional的配置
	 * propagation  默认为required，也是用得最多的
	 * readOnly     默认为false，设置为true表示只做查询（可提高查询效率）
	 * </pre>
	 */
	// @Transactional(propagation = Propagation.REQUIRED, readOnly = true)
	public User get(Integer id) {
		User u = userDao.load(id);
		User user = new User();
		user.setId(u.getId());
		user.setName(u.getName());
		user.setPhoto(u.getPhoto());
		return user;
	}

	public List<User> list() {
		return null;
	}

	public User login(String code, String password) {
		return userDao.login(code, password);
	}

	public Integer register(User user) {
		return userDao.register(user);
	}

	public List<Menu> getMenu(Integer roleId) {
		return menuDao.getMenu(roleId);
	}

	public PageModel<Object[]> getUserList(Integer pageNo) {
		return userDao.getUserList(pageNo);
	}

	public void deleteUserInfo(Integer id) {
		userDao.deleteUserInfo(id);
	}

}
